export function isAuth(tableName, key) {
    let role = localStorage.getItem("UserTableName");
    let menus = [{
        "backMenu": [{
            "child": [{
                "appFrontIcon": "cuIcon-link",
                "buttons": ["新增", "查看", "修改", "删除"],
                "menu": "学生",
                "menuJump": "列表",
                "tableName": "xuesheng"
            }], "menu": "学生管理"
        }, {
            "child": [{
                "appFrontIcon": "cuIcon-clothes",
                "buttons": ["新增", "查看", "修改", "删除"],
                "menu": "教师",
                "menuJump": "列表",
                "tableName": "jiaoshi"
            }], "menu": "教师管理"
        }, {
            "child": [{
                "appFrontIcon": "cuIcon-goods",
                "buttons": ["查看", "修改", "删除"],
                "menu": "班级信息",
                "menuJump": "列表",
                "tableName": "banjixinxi"
            }], "menu": "班级信息管理"
        }, {
            "child": [{
                "appFrontIcon": "cuIcon-phone",
                "buttons": ["新增", "查看", "修改", "删除"],
                "menu": "课程类型",
                "menuJump": "列表",
                "tableName": "kechengleixing"
            }], "menu": "课程类型管理"
        }, {
            "child": [{
                "appFrontIcon": "cuIcon-rank",
                "buttons": ["查看", "修改", "删除", "审核", "查看评论"],
                "menu": "课程信息",
                "menuJump": "列表",
                "tableName": "kechengxinxi"
            }], "menu": "课程信息管理"
        }, {
            "child": [{
                "appFrontIcon": "cuIcon-discover",
                "buttons": ["查看", "修改", "删除", "首页总数", "首页统计"],
                "menu": "参加课程",
                "menuJump": "列表",
                "tableName": "canjiakecheng"
            }], "menu": "参加课程管理"
        }, {
            "child": [{
                "appFrontIcon": "cuIcon-list",
                "buttons": ["查看", "修改", "删除", "首页总数", "首页统计"],
                "menu": "班级学生",
                "menuJump": "列表",
                "tableName": "banjixuesheng"
            }], "menu": "班级学生管理"
        }, {
            "child": [{
                "appFrontIcon": "cuIcon-wenzi",
                "buttons": ["查看", "修改", "删除", "审核", "查看评论"],
                "menu": "课程视频",
                "menuJump": "列表",
                "tableName": "kechengshipin"
            }], "menu": "课程视频管理"
        }, {
            "child": [{
                "appFrontIcon": "cuIcon-phone",
                "buttons": ["查看", "修改", "删除", "首页总数", "首页统计"],
                "menu": "学习记录",
                "menuJump": "列表",
                "tableName": "xuexijilu"
            }], "menu": "学习记录管理"
        }, {
            "child": [{
                "appFrontIcon": "cuIcon-group",
                "buttons": ["查看", "修改", "删除"],
                "menu": "在线讨论",
                "tableName": "forum"
            }], "menu": "在线讨论"
        }, {
            "child": [{
                "appFrontIcon": "cuIcon-copy",
                "buttons": ["新增", "查看", "修改", "删除"],
                "menu": "测试管理",
                "tableName": "exampaper"
            }], "menu": "测试管理"
        }, {
            "child": [{
                "appFrontIcon": "cuIcon-cardboard",
                "buttons": ["新增", "查看", "修改", "删除"],
                "menu": "试题管理",
                "tableName": "examquestion"
            }], "menu": "试题管理"
        }, {
            "child": [{
                "appFrontIcon": "cuIcon-news",
                "buttons": ["新增", "查看", "修改", "删除"],
                "menu": "公告信息",
                "tableName": "news"
            }, {
                "appFrontIcon": "cuIcon-copy", "buttons": ["查看", "修改"], "menu": "关于我们", "tableName": "aboutus"
            }, {
                "appFrontIcon": "cuIcon-explore",
                "buttons": ["查看", "修改"],
                "menu": "轮播图管理",
                "tableName": "config"
            }], "menu": "系统管理"
        }, {
            "child": [{
                "appFrontIcon": "cuIcon-full", "buttons": ["查看"], "menu": "错题本", "tableName": "examfailrecord"
            }, {"appFrontIcon": "cuIcon-read", "buttons": ["查看"], "menu": "测试记录", "tableName": "examrecord"}],
            "menu": "测试管理"
        }],
        "frontMenu": [{
            "child": [{
                "appFrontIcon": "cuIcon-pic",
                "buttons": ["查看"],
                "menu": "班级信息列表",
                "menuJump": "列表",
                "tableName": "banjixinxi"
            }], "menu": "班级信息模块"
        }, {
            "child": [{
                "appFrontIcon": "cuIcon-pic",
                "buttons": ["查看", "参加", "学习"],
                "menu": "课程信息列表",
                "menuJump": "列表",
                "tableName": "kechengxinxi"
            }], "menu": "课程信息模块"
        }, {
            "child": [{
                "appFrontIcon": "cuIcon-vipcard",
                "buttons": ["查看", "学习"],
                "menu": "课程视频列表",
                "menuJump": "列表",
                "tableName": "kechengshipin"
            }], "menu": "课程视频模块"
        }],
        "hasBackLogin": "是",
        "hasBackRegister": "否",
        "hasFrontLogin": "否",
        "hasFrontRegister": "否",
        "roleName": "管理员",
        "tableName": "users"
    }, {
        "backMenu": [{
            "child": [{
                "appFrontIcon": "cuIcon-discover",
                "buttons": ["查看", "删除"],
                "menu": "参加课程",
                "menuJump": "列表",
                "tableName": "canjiakecheng"
            }], "menu": "参加课程管理"
        }, {
            "child": [{
                "appFrontIcon": "cuIcon-phone",
                "buttons": ["查看"],
                "menu": "学习记录",
                "menuJump": "列表",
                "tableName": "xuexijilu"
            }], "menu": "学习记录管理"
        }],
        "frontMenu": [{
            "child": [{
                "appFrontIcon": "cuIcon-pic",
                "buttons": ["查看"],
                "menu": "班级信息列表",
                "menuJump": "列表",
                "tableName": "banjixinxi"
            }], "menu": "班级信息模块"
        }, {
            "child": [{
                "appFrontIcon": "cuIcon-pic",
                "buttons": ["查看", "参加", "学习"],
                "menu": "课程信息列表",
                "menuJump": "列表",
                "tableName": "kechengxinxi"
            }], "menu": "课程信息模块"
        }, {
            "child": [{
                "appFrontIcon": "cuIcon-vipcard",
                "buttons": ["查看", "学习"],
                "menu": "课程视频列表",
                "menuJump": "列表",
                "tableName": "kechengshipin"
            }], "menu": "课程视频模块"
        }],
        "hasBackLogin": "否",
        "hasBackRegister": "否",
        "hasFrontLogin": "是",
        "hasFrontRegister": "是",
        "roleName": "学生",
        "tableName": "xuesheng"
    }, {
        "backMenu": [{
            "child": [{
                "appFrontIcon": "cuIcon-goods",
                "buttons": ["新增", "查看", "修改", "删除"],
                "menu": "班级信息",
                "menuJump": "列表",
                "tableName": "banjixinxi"
            }], "menu": "班级信息管理"
        }, {
            "child": [{
                "appFrontIcon": "cuIcon-rank",
                "buttons": ["新增", "查看", "修改", "删除", "查看评论"],
                "menu": "课程信息",
                "menuJump": "列表",
                "tableName": "kechengxinxi"
            }], "menu": "课程信息管理"
        }, {
            "child": [{
                "appFrontIcon": "cuIcon-discover",
                "buttons": ["查看", "删除", "审核", "添加学生", "首页总数", "首页统计"],
                "menu": "参加课程",
                "menuJump": "列表",
                "tableName": "canjiakecheng"
            }], "menu": "参加课程管理"
        }, {
            "child": [{
                "appFrontIcon": "cuIcon-list",
                "buttons": ["查看", "修改", "删除", "首页总数", "首页统计"],
                "menu": "班级学生",
                "menuJump": "列表",
                "tableName": "banjixuesheng"
            }], "menu": "班级学生管理"
        }, {
            "child": [{
                "appFrontIcon": "cuIcon-wenzi",
                "buttons": ["新增", "查看", "修改", "删除", "查看评论"],
                "menu": "课程视频",
                "menuJump": "列表",
                "tableName": "kechengshipin"
            }], "menu": "课程视频管理"
        }, {
            "child": [{
                "appFrontIcon": "cuIcon-phone",
                "buttons": ["查看", "首页总数", "首页统计"],
                "menu": "学习记录",
                "menuJump": "列表",
                "tableName": "xuexijilu"
            }], "menu": "学习记录管理"
        }, {
            "child": [{
                "appFrontIcon": "cuIcon-copy",
                "buttons": ["新增", "查看", "修改", "删除"],
                "menu": "测试管理",
                "tableName": "exampaper"
            }], "menu": "测试管理"
        }, {
            "child": [{
                "appFrontIcon": "cuIcon-cardboard",
                "buttons": ["新增", "查看", "修改", "删除"],
                "menu": "试题管理",
                "tableName": "examquestion"
            }], "menu": "试题管理"
        }, {
            "child": [{
                "appFrontIcon": "cuIcon-read", "buttons": ["查看"], "menu": "测试记录", "tableName": "examrecord"
            }, {"appFrontIcon": "cuIcon-full", "buttons": ["查看"], "menu": "错题本", "tableName": "examfailrecord"}],
            "menu": "测试管理"
        }],
        "frontMenu": [{
            "child": [{
                "appFrontIcon": "cuIcon-pic",
                "buttons": ["查看"],
                "menu": "班级信息列表",
                "menuJump": "列表",
                "tableName": "banjixinxi"
            }], "menu": "班级信息模块"
        }, {
            "child": [{
                "appFrontIcon": "cuIcon-pic",
                "buttons": ["查看", "参加", "学习"],
                "menu": "课程信息列表",
                "menuJump": "列表",
                "tableName": "kechengxinxi"
            }], "menu": "课程信息模块"
        }, {
            "child": [{
                "appFrontIcon": "cuIcon-vipcard",
                "buttons": ["查看", "学习"],
                "menu": "课程视频列表",
                "menuJump": "列表",
                "tableName": "kechengshipin"
            }], "menu": "课程视频模块"
        }],
        "hasBackLogin": "是",
        "hasBackRegister": "是",
        "hasFrontLogin": "否",
        "hasFrontRegister": "否",
        "roleName": "教师",
        "tableName": "jiaoshi"
    }];
    for (let i = 0; i < menus.length; i++) {
        if (menus[i].tableName == role) {
            for (let j = 0; j < menus[i].frontMenu.length; j++) {
                for (let k = 0; k < menus[i].frontMenu[j].child.length; k++) {
                    if (tableName == menus[i].frontMenu[j].child[k].tableName) {
                        let buttons = menus[i].frontMenu[j].child[k].buttons.join(',');
                        return buttons.indexOf(key) !== -1 || false
                    }
                }
            }
        }
    }
    return false;
}

/**
 *  * 获取当前时间（yyyy-MM-dd hh:mm:ss）
 *   */
export function getCurDateTime() {
    let currentTime = new Date(), year = currentTime.getFullYear(),
        month = currentTime.getMonth() + 1 < 10 ? '0' + (currentTime.getMonth() + 1) : currentTime.getMonth() + 1,
        day = currentTime.getDate() < 10 ? '0' + currentTime.getDate() : currentTime.getDate(),
        hour = currentTime.getHours(), minute = currentTime.getMinutes(), second = currentTime.getSeconds();
    return year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
}

/**
 *  * 获取当前日期（yyyy-MM-dd）
 *   */
export function getCurDate() {
    let currentTime = new Date(), year = currentTime.getFullYear(),
        month = currentTime.getMonth() + 1 < 10 ? '0' + (currentTime.getMonth() + 1) : currentTime.getMonth() + 1,
        day = currentTime.getDate() < 10 ? '0' + currentTime.getDate() : currentTime.getDate();
    return year + "-" + month + "-" + day;
}
